﻿using AutoMapper;
using Business.WriteAPI.Application.FarmEnterprises;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.WriteAPI.Application.Slaughtes
{
    public class SlaughteUpdRequestHandler : IRequestHandler<SlaughteUpdRequestModel, APIResult>
    {
        private IBaseRepository<Slaughte> slaughteRepository;
        private readonly IMapper mapper;
        public SlaughteUpdRequestHandler(IBaseRepository<Slaughte> slaughteRepository, IMapper mapper)
        {
            this.slaughteRepository = slaughteRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(SlaughteUpdRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.UpdSuccess;
            result.Msg = "编辑成功";

            Slaughte slaughte = mapper.Map<Slaughte>(request);
            slaughteRepository.Update(slaughte);

            return Task.FromResult(result);
        }
    }
    public class SlaughteUpdRequestModel:IRequest<APIResult>
    {
        public int Id { get; set; }
        public string ProductCode { get; set; }
        public string ProductionBatch { get; set; }
        public string AverageWeight { get; set; }
        public DateTime EntryTime { get; set; }
        public DateTime SlaughteTime { get; set; }
        public string Creator { get; set; }
        public DateTime CreateTime { get; set; }
    }
}
